package com.huifaapp.mall.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.blankj.utilcode.util.SPUtils;
import com.google.gson.Gson;
import com.huifaapp.mall.R;
import com.huifaapp.mall.adapter.TnallShopkeeperDetaAdapter;
import com.huifaapp.mall.afinal.SPConstants;
import com.huifaapp.mall.api.ApiManager;
import com.huifaapp.mall.bean.Tmall_StoreHEADBean;
import com.huifaapp.mall.uitils.AUniqueIdentifier;
import com.huifaapp.mall.uitils.CircleTransform;
import com.jude.rollviewpager.adapter.StaticPagerAdapter;
import com.squareup.okhttp.Request;
import com.squareup.picasso.Picasso;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

import java.util.ArrayList;
import java.util.List;

import static com.huifaapp.mall.R2.id.avatarImageView;

/**
 * Created by duanyu on 2017/12/29.
 */

public class TmllshopkeeperDetailActivity extends AppCompatActivity implements View.OnClickListener{

    private ImageView activity_tmll_detail_return;
    private TabLayout activity_tmall_detail_tab;
    private ViewPager activity_tmall_detail_viewPager;
    private List tablist;
    private String userImg;
    private String userNickName;
    private String balcance;
    private String myteamNum;
    private String preProfit;
    private String actualProfit;
    private String orderNum;
    private ImageView activity_tmll_detail_userImg;
    private TextView activity_tmll_detail_userNickName;
    private TextView activity_tmll_detail_balcance;
    private TextView activity_tmll_detail_myteamNum;
    private TextView activity_tmll_detail_preProfit;
    private TextView activity_tmll_detail_orderNum;
    private TextView activity_tmll_detail_actualProfit;
    private LinearLayout ll_yaoqingruzhu;
    private LinearLayout ll_yaoqingvip;
    private Tmall_StoreHEADBean.DataBean data;
    private  String  HEADURL= ApiManager.BASE_NIUPAI_URL+"users/yunindex";
    private LinearLayout tmll_detailye_balanceccccc_biaobiao;
    private LinearLayout ll_tmmllshopkeeper_mytudui;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tmmllshopkeeper_detail);
       Intent  intent = getIntent();
        userImg = intent.getStringExtra("userImg");
        userNickName = intent.getStringExtra("userNickName");
        balcance = intent.getStringExtra("balcance");
//        myteamNum = intent.getStringExtra("myteamNum");
        preProfit = intent.getStringExtra("preProfit");
        actualProfit = intent.getStringExtra("actualProfit");
        orderNum = intent.getStringExtra("orderNum");
        initView();
        initHeadData();
        initTab();

        activity_tmll_detail_return.setOnClickListener(this);
    }
    private void initHeadData() {
        Picasso.with(this).load(userImg).transform(new CircleTransform()).into(activity_tmll_detail_userImg);
        activity_tmll_detail_userNickName.setText(userNickName);
        initHeadHttp();
//        activity_tmll_detail_balcance.setText(balcance);
      //  activity_tmll_detail_myteamNum.setText(myteamNum);
//        try {
//            activity_tmll_detail_preProfit.setText(preProfit);
//        }catch (Exception e){
//
//        }

//        activity_tmll_detail_actualProfit.setText(actualProfit);
//        activity_tmll_detail_orderNum.setText(orderNum);

    }

    private void initHeadHttp() {
        OkHttpUtils.get().addParams("token", SPUtils.getInstance().getString(SPConstants.KEY_USER_TOKEN)).addParams("appId", AUniqueIdentifier.getDeviceId(TmllshopkeeperDetailActivity.this)).url(HEADURL)
                .build().execute(new StringCallback() {
            @Override
            public void onError(Request request, Exception e) {

            }

            @Override
            public void onResponse(String response) {
                android.util.Log.e("OOOOOOOOOOO",response);
                Gson gson=new Gson();
                Tmall_StoreHEADBean tmall_storeHEADBean = gson.fromJson(response, Tmall_StoreHEADBean.class);

                data = tmall_storeHEADBean.getData();

                if(tmall_storeHEADBean.getCode().equals("10000")) {
                    try {
//                        Picasso.with(TmllshopkeeperDetailActivity.this).load(data.getUserImg()).transform(new CircleTransform()).into(avatarImageView);
//                        store_textView.setText(data.getUserNickName());
                        activity_tmll_detail_balcance.setText(data.getBalcance() + "");
                        // tmall_shopkeeper_team.setText(data.getMyteamNum() + "");
                        activity_tmll_detail_myteamNum.setText(data.getPreProfit() + "");
                        activity_tmll_detail_actualProfit.setText(data.getActualProfit() + "");
                        activity_tmll_detail_orderNum.setText(data.getOrderNum() + "");
                    } catch (Exception e) {
                        //Picasso.with(getActivity()).load(data.getUserImg()).transform(new CircleTransform()).into(avatarImageView);
//                        store_textView.setText("");
                        activity_tmll_detail_balcance.setText(0+ "");
                        // tmall_shopkeeper_team.setText(data.getMyteamNum() + "");
                        activity_tmll_detail_myteamNum.setText(0+ "");
                        activity_tmll_detail_actualProfit.setText(0+ "");
                        activity_tmll_detail_orderNum.setText(0+ "");
                    }
                }else  if (tmall_storeHEADBean.getCode().equals("10001")){
//                    Intent intent=new Intent(getActivity(),LoginActivity.class);
//                    startActivity(intent);
                }



            }
        });
    }
    private void initTab() {
        tablist = new ArrayList();
        tablist.add("预估收益明细");
        tablist.add("累计收益明细");
        TnallShopkeeperDetaAdapter TnallShopkeeperDetaAdapter=new TnallShopkeeperDetaAdapter(getSupportFragmentManager(),tablist);
        activity_tmall_detail_viewPager.setAdapter(TnallShopkeeperDetaAdapter);
        activity_tmall_detail_tab.setupWithViewPager(activity_tmall_detail_viewPager);
    }

    private void initView() {
        activity_tmll_detail_return = (ImageView) findViewById(R.id.activity_tmll_detail_return);
        activity_tmall_detail_tab = (TabLayout) findViewById(R.id.activity_tmall_detail_tab);
        activity_tmall_detail_viewPager = (ViewPager) findViewById(R.id.activity_tmall_detail_ViewPager);
        activity_tmll_detail_userImg = (ImageView) findViewById(R.id.activity_tmll_detail_userImg);
        activity_tmll_detail_userNickName = (TextView) findViewById(R.id.activity_tmll_detail_userNickName);
        activity_tmll_detail_balcance = (TextView) findViewById(R.id.activity_tmll_detail_balcance);
        activity_tmll_detail_myteamNum = (TextView) findViewById(R.id.activity_tmll_detail_myteamNum);
//        activity_tmll_detail_preProfit = (TextView) findViewById(R.id.activity_tmll_detail_preProfit);
        activity_tmll_detail_actualProfit = (TextView) findViewById(R.id.activity_tmll_detail_actualProfit);
        activity_tmll_detail_orderNum = (TextView) findViewById(R.id.activity_tmll_detail_orderNum);
        ll_tmmllshopkeeper_mytudui= (LinearLayout) findViewById(R.id.ll_tmmllshopkeeper_mytudui);
        ll_tmmllshopkeeper_mytudui.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent Intent=new Intent(TmllshopkeeperDetailActivity.this,Tmall_shopkeeperFragment_team.class);
                startActivity(Intent);

            }
        });
        ll_yaoqingruzhu= (LinearLayout) findViewById(R.id.ll_yaoqingruzhu);
        ll_yaoqingruzhu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(TmllshopkeeperDetailActivity.this,InviteCollarNowActivity.class);
                startActivity(intent);
            }
        });
        ll_yaoqingvip= (LinearLayout) findViewById(R.id.ll_yaoqingvip);
        ll_yaoqingvip.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(TmllshopkeeperDetailActivity.this,InvitationVIPActivity.class);
                startActivity(intent);
            }
        });
        tmll_detailye_balanceccccc_biaobiao= (LinearLayout) findViewById(R.id.tmll_detailye_balanceccccc_biaobiao);
        tmll_detailye_balanceccccc_biaobiao.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(TmllshopkeeperDetailActivity.this,DepositActivity.class);
                startActivity(intent);
            }
        });
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.activity_tmll_detail_return:
                finish();
                break;
            case R.id.ll_yaoqingruzhu:
                Intent intent=new Intent(TmllshopkeeperDetailActivity.this,InviteCollarNowActivity.class);
                startActivity(intent);
                break;
            case R.id.ll_yaoqingvip:
                Intent intent1=new Intent(TmllshopkeeperDetailActivity.this,InvitationVIPActivity.class);
                startActivity(intent1);
                break;
        }
    }
}
